<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ClassBase extends Model
{
    protected $table = 'class_base';

    public static $modify = true;

    public function class_to_info()
    {
        return $this->belongsTo('App\Models\ClassBaseInfo', 'class_base_id');
    }

    public function carousel_image()
    {
        return $this->hasMany('App\Models\CarouselImage','class_base_id','id');
    }

    //查询店铺名
    public function store()
    {
        return $this->hasOne('App\Models\Store','id','store_id');
    }

    //課程編號
    public function numbering()
    {
        return $this->hasOne(ClassBaseNumbering::class,'id','class_base_numbering_id');
    }


    /**
     * 获取器
     */
    public function getClassCoveAttribute($value)
    {
        if(!empty($value)) {
            if(self::$modify)return getDomain() . '/' . $value;
            if(!self::$modify)return $value;
        }else{
            return null;
        }
    }

    /**
     * 获取器
     */
    public function getClassVideoAttribute($value)
    {
        if(!empty($value)) {
            if(self::$modify)return getDomain() . '/' . $value;
            if(!self::$modify)return $value;
        }else{
            return null;
        }
    }

    /**
     * 获取器 class_tab array
     */
    public function getClassTabAttribute($value)
    {
        if(!empty($value)){
            return explode(',',$value);
        }
    }

    /**
     * 轮播图设置器
     */
    public function setClassImgAttribute($value)
    {
        if (is_array($value)) {
            $this->attributes['class_img'] = trim(implode(";", $value),';');
        }
    }

    /**
     * 获取器
     */
    public function getUserRankIdAttribute($value)
    {
        if(!empty($value)) {
            return explode(',', $value);
        }else{
            return $value = [];
        }
    }

}
